
import request from '@/utils/http/index';



/**
 * api地址
 */
enum Api {
  attachmentSearch = '/attachment/search',
  AttachmentPreviewById = '/attachment/previewById',
  AttachmentDownloadById = '/attachment/downloadById',
  AttachmentDeleteById = '/attachment/deleteById',
  AttachmentPreview = '/attachment/preview',
  AttachmentDownload = '/attachment/download',
  CheckAttachmentExist = '/attachment/checkAttachmentExist',
  NodeImportHistory ='/attachment/historyImport',
}

export const attachmentSearch =  (data: any)=>{
  return request.post({url: Api.attachmentSearch,data});
}

export const checkAttachmentExist =  (data: any)=>{
  return request.post({url: Api.CheckAttachmentExist,data});
}

// 获取节点附件的方法
export const attachmentDownload = (data: { nodeId: string,attachmentId?: string }) => {
  return request.download({ url: Api.AttachmentDownload, params: data });
}

export const attachmentPreview = (data: { nodeId: string,attachmentId?: string }) => {
  return request.download({ url: Api.AttachmentPreview, params: data });
}


export const attachmentDownloadById = (data: { attachmentId: string }) => {
  return request.download({ url: Api.AttachmentDownloadById, params: data });
}

export const attachmentPreviewById = (data: { attachmentId: string }) => {
  return request.download({ url: Api.AttachmentPreviewById, params: data });
}

// export const deleteAttachment = (data: { nodeId: string,attachmentId: string }) => {
//   return request.post({url: Api.AttachmentDeleteById, params: data });
// }

export const deleteAttachment = (data: { nodeId: string,attachmentId: string }) => {
  return request.post({url: Api.AttachmentDeleteById, data });
}

// export const attachmentDownload = (data: { nodeId: string,attachmentId: string}) => {
//   return request.download({ url: Api.AttachmentDownload, params: data }).then(res => {
//     // 假设 response.data 是 Blob 类型的数据
//     // return URL.createObjectURL(new Blob([res]));
//     return URL.createObjectURL(res);
//   });
// };

export const getNodeHistory = (data: any)=>{
  return request.post({url: Api.NodeImportHistory,data});
}
